package com.eastfair.venueservice.controller;

import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.core.exception.BizException;
import com.eastfair.venueservice.dto.*;
import com.eastfair.venueservice.entity.BondPayRecord;
import com.eastfair.venueservice.service.BondPayRecordService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.eastfair.annotation.annotation.security.PreAuth;

import com.eastfair.boot.request.PageParams;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * <p>
 * 前端控制器
 * 保证金付款记录
 * </p>
 *
 * @author lyw
 * @date 2023-02-17
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/bondPayRecord")
@Api(value = "BondPayRecord", tags = "保证金付款记录")
@PreAuth(replace = "venueservice:bondPayRecord:")
public class BondPayRecordController extends SuperController<BondPayRecordService, Long, BondPayRecord, BondPayRecordPageQuery, BondPayRecordSaveDTO, BondPayRecordUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private BondPayRecordService bondPayRecordService;

    @Override
    public void handlerResult(IPage<BondPayRecord> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<BondPayRecord> bondPayRecordList = list
                .stream()
                .map((map) -> BondPayRecord.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(bondPayRecordList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<BondPayRecordPageQuery> params) {
        BondPayRecordPageQuery pageQuery = params.getModel();
    }

    /**
     * 保存保证金支付记录
     * @param bondPayRecordDTO
     * @return
     */
    @SysLog("支付保证金")
    @ApiOperation(value = "保存保证金支付记录")
    @PostMapping(value = "/saveBondPayRecordInfo")
    public R<Boolean> saveBondPayRecordInfo(@RequestBody BondPayRecordDTO bondPayRecordDTO){
        log.info("saveBondPayRecordInfo - 保存保证金支付记录, bondPayRecordDTO={}", bondPayRecordDTO);
        try {
            return R.success(bondPayRecordService.saveBondPayRecordInfo(bondPayRecordDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 主场保证金保存支付记录.
     *
     * @param bondPayRecordDTO the bond pay record dto
     * @return the r
     */
    @SysLog("支付保证金")
    @ApiOperation(value = "保存保证金支付记录")
    @PostMapping(value = "/save/for/homeBondManage")
    public R<Boolean> saveForHomeBondManage(@RequestBody BondPayRecordDTO bondPayRecordDTO){
        log.info("saveForHomeBondManage - 主场保证金保存支付记录, bondPayRecordDTO={}", bondPayRecordDTO);
        try {
            return R.success(bondPayRecordService.saveForHomeBondManage(bondPayRecordDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }
}
